<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Session;
use app\common\model\Users;
class Login extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
{

if (IS_POST){


        $post = input('post.');
        $user = Users::where('username', '=', $post['username'])->where('is_admin', '=', 0)->find();

        if (!$user || $user['password'] != md5($post['password'])) {
            $this->error('用户名或者密码错误');
        } else {
            Session::set('homeuser', $user->toArray());

            $this->success('登陆成功', '/');
        }

    }

    return view();

}


    public function layout()
    {

        // 清除当前请求有效的session
        Session::delete('homeuser');
//        Session::delete('cart');
        $this->success('退出成功', '/');

    }


}
